package com.example.demo.service;


import com.example.demo.mapper.BlogInfoMapper;
import com.example.demo.mapper.UserInfoMapper;
import com.example.demo.model.BlogInfo;
import com.example.demo.model.UserInfo;
import io.jsonwebtoken.lang.Assert;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class UserService {

    @Autowired
    private UserInfoMapper userInfoMapper;

    @Autowired
    private BlogInfoMapper blogInfoMapper;

    public UserInfo selectUserInfoByName(String userName) {
       return userInfoMapper.selectByName(userName);
    }

    public UserInfo selectUserInfoById(Integer userId) {
        return userInfoMapper.selectById(userId);
    }

    public UserInfo selectAuthorByBlogId(Integer blogId) {
        //1.根据博客id,获取作者id
        BlogInfo blogInfo = blogInfoMapper.selectById(blogId);
        Assert.notNull(blogInfo,"blogInfo不能为null");

        //2.根据作者id,获取作者信息
        UserInfo userInfo = userInfoMapper.selectById(blogInfo.getUserId());
        return userInfo;
    }
}
